<?php

namespace app\admin\service;

use app\admin\model\GoodsCategory;

class GoodsCategoryService
{

    public function getCategoryList()
    {
        $model = new GoodsCategory();
        $categories = $model->withOutField('desc')->select();
        
        return  !$categories->isEmpty() ? generateTreeOption($categories->toArray()) : [];
        
    }

    public function findCategory($id)
    {
        $model = new GoodsCategory();
        $category = $model->withOutField('create_time,update_time')->find($id);
    
        
        return $category;
        
    }

    public function getCategoryOption($fliter = false)
    {
        $model = new GoodsCategory();
        $query = $model->field('id,parent_id,name');

        if($fliter){
            $query->where('status',1);
        }

        $categories = $query->select();
        
        return  !$categories->isEmpty() ? generateTreeOption($categories->toArray()) : [];
        
    }

    // 查询是否有子分类

    public function categorySonExsits($id)
    {   
        $model = new GoodsCategory();
        $sonCategory =$model->field('id')->where('parent_id',$id)->find();

        return !empty($sonCategory) ? true : false; 
    }
    

    
}